<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="../css/mui.min.css" rel="stylesheet" />

		<style>
			ul {
				font-size: 14px;
				color: #8f8f94;
			}
			.mui-btn {
				padding: 10px;
			}
			.link-area {
				display: block;
				margin-top: 25px;
				text-align: center;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav" style="padding-right: 15px;">
			<h1 class="mui-title">注册审核</h1>
		</header>
		<div class="mui-content">
			<div class="mui-content-padded">
				<p>
					您好 <span id='realName'></span>，您已成功注册。
					<ul>
						<li>您当前账号注册码为：<span id='info'></span>。</li>
						<li>您可以输入账号注册码验证注册是否通过审核。</li>
						<li>注册审核通过之后您可以直接登录系统。</li>
						<li>注册审核通过之后将不会出现此页面。</li>
					</ul>
				</p>
				<!--<button  class="mui-btn mui-btn-block mui-btn-primary">设置</button>-->
				<!--
				<button id='exit' class="mui-btn mui-btn-block mui-btn-green">关闭</button>
                <button id='logout' class="mui-btn mui-btn-red mui-btn-block">注销登录</button>
                -->
			</div>
			<form id='login-form' class="mui-input-group">
				<div class="mui-input-row">
					<label>账号</label>
					<input id='account' type="text" class="mui-input-clear mui-input" placeholder="请输入账号">
				</div>
				<div class="mui-input-row">
					<label>注册码</label>
					<input id='regCode' name='regCode' type="text" class="mui-input-clear mui-input" placeholder="请输入注册码">
				</div>
			</form>
			
			<div class="mui-content-padded">
				<button id='checkNum' class="mui-btn mui-btn-block mui-btn-primary">账号查询</button>
				<div class="link-area"><a id='regUpdate'>注册修改</a> <span class="spliter">|</span> <a id='loginSys'>登录系统</a>
				</div>
			</div>
		</div>
		<script src="../js/common.js"></script>
		<script src="../js/mui.min.js"></script>
		<script src="../js/app.js"></script>
		<script>
			mui.init({
			swipeBack:true //启用右滑关闭功能
		});
			(function($, doc) {
				$.init();
				$.plusReady(function() {
					var users = JSON.parse(localStorage.getItem('$users') || '[]');
					var registCode;
					var realName ;
					var checkStatus ;
					var password ;//未加密的密码
					var ifLogin ;
					users.some(function(user) {
						registCode =  user.registCode;
						
					});
					users.some(function(user) {
						realName =  user.realName;
						checkStatus = user.checkStatus;
						password = user.password;
						ifLogin = user.ifLogin;
					});
					
					var info = document.getElementById("info");
					var rName = document.getElementById("realName");
					if(realName!=undefined&&realName!=""){
						rName.innerHTML = realName;
					}
					var regCodeBox=document.getElementById('regCode');
					if(registCode!=undefined&&registCode!=""){
						info.innerHTML = "您已成功注册，注册码为："+registCode;
						document.querySelector('input[name="regCode"]').value=registCode;
					}
					var updateRegButton=document.getElementById('regUpdate');
					updateRegButton.addEventListener('tap', function(event) {
						$.openWindow({
							url: 'reg.html',
							id: 'reg'+new Date().getMilliseconds(),
							preload: true,
							show: {
								aniShow: 'pop-in'
							},
							styles: {
								popGesture: 'hide'
							},
							waiting: {
								autoShow: false
							},
							extras:{
								ifUpdate:'update'
							}
						});
					}, false);
					var loginSysButton=document.getElementById('loginSys');
					loginSysButton.addEventListener('tap', function(event) {
						$.openWindow({
							url: 'login.html',
							id: 'login'+new Date().getMilliseconds(),
							preload: true,
							show: {
								aniShow: 'pop-in'
							},
							styles: {
								popGesture: 'hide'
							},
							waiting: {
								autoShow: false
							}
						});
						/*var u= JSON.parse(localStorage.getItem('$users') || '[]');
						var uName;
						users.some(function(user) {
							uName=user.userName;
						});
						var regInfo = {
							userName: uName,
							registCode: regCodeBox.value,
							
						};
						//根据用户名和注册码查询数据，返回整个对象
						
						var url=baseUrl+"/dapi/muser/getUserByReg";
						mui.ajax(url,{
						    data:regInfo,
						    dataType:'json',//服务器返回json格式数据
						    type:'post',//HTTP请求类型	
						    timeout:10000,//超时时间设置为10秒；
						    headers:{'Content-Type':'application/json'},                  
						    success:function(data){
						    	var chStatus= data.data.checkStatus;
						    	if(chStatus=='0'){
						    		plus.nativeUI.toast('暂未审核请耐心等待');
						    		return;
						    	}else if(chStatus=='1'){//审核通过
						    		$.openWindow({
										url: 'login.html',
										id: 'login',
										preload: true,
										show: {
											aniShow: 'pop-in'
										},
										styles: {
											popGesture: 'hide'
										},
										waiting: {
											autoShow: false
										}
									});
						    	}else{//2
						    		plus.nativeUI.toast('审核未通过，请修改注册信息继续注册');
						    		return;
						    	}
						    	
						    	//重新覆盖本机存储基本信息
						    	var userInfo={
						    		id:data.data.id,
						    		userName: data.data.userName,
									password: password,
									phone: data.data.phone,
									realName: data.data.realName,
									registCode:data.data.registCode,
									checkStatus:data.data.checkStatus,
									ifLogin:ifLogin
						    	};
						    	var users = JSON.parse(localStorage.getItem('$users') || '[]');
								users.push(userInfo);
								localStorage.setItem('$users', JSON.stringify(users));
						    },
						    error:function(data){
						    	plus.nativeUI.toast('请稍后再试！！');
						    }
						});*/
					}, false);
					var checkNumButton=document.getElementById('checkNum');
					var accountBox=document.getElementById('account');
					checkNumButton.addEventListener('tap', function(event) {
						if(accountBox==""||accountBox==null){
							mui.alert("请输入用户名");
							return;
						}
						var regInfo = {
							userName: accountBox.value,
							registCode: regCodeBox.value
						};
						//根据用户名和注册码查询数据，返回整个对象
						var url=baseUrl+"/dapi/muser/getUserByReg";
						mui.ajax(url,{
						    data:regInfo,
						    dataType:'json',//服务器返回json格式数据
						    type:'post',//HTTP请求类型	
						    timeout:10000,//超时时间设置为10秒；
						    headers:{'Content-Type':'application/json'},                  
						    success:function(data){
						    	var chStatus= data.data.checkStatus;
						    	if(chStatus=='0'){
						    		plus.nativeUI.toast('暂未审核请耐心等待');
						    	}else if(chStatus=='1'){//审核通过
						    		plus.nativeUI.toast('审核通过，可直接登录系统');
						    	}else if(chStatus=='2'){//2
						    		plus.nativeUI.toast('审核未通过，请修改注册信息继续注册');
						    	}else{
						    		plus.nativeUI.toast('用户名与注册码不匹配');
						    	}
						    	
						    	//重新覆盖本机存储基本信息
						    	var userInfo={
						    		id:data.data.id,
						    		userName: data.data.userName,
									password: password,
									phone: data.data.phone,
									realName: data.data.realName,
									registCode:data.data.registCode,
									checkStatus:data.data.checkStatus,
									companyName:data.data.companyName,
									xydm:data.data.xydm,
									agentCompany:data.data.agentId,
									ifLogin:ifLogin
						    	};
						    	var users = JSON.parse(localStorage.getItem('$users') || '[]');
								users.push(userInfo);
								localStorage.setItem('$users', JSON.stringify(users));
						    },
						    error:function(data){
						    	plus.nativeUI.toast('查询失败，请稍后再试！！');
						    }
						});
						
					});
				});
			}(mui, document));
		</script>
	</body>

</html>